package com.tihi.sinasharedemo;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Toast;

import com.tihi.sina.share.ShareToSinaWeiboInvoker;
import com.tihi.sina.share.ShareToSinaWeiboInvoker.ISinaWeiboListener;
import com.tihi.sinademo.R;

/**
 * 主界面
 * @author apple
 *
 */
public class MainActivity extends Activity implements OnClickListener{
	private ShareToSinaWeiboInvoker shareToSinaWeiboInvoker;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main_act_layout);
        
        findViewById(R.id.shareText).setOnClickListener(this);
        findViewById(R.id.shareTextAndImage).setOnClickListener(this);
        
        shareToSinaWeiboInvoker = new ShareToSinaWeiboInvoker(this, new ISinaWeiboListener() {
			
			@Override
			public void onSucess() {
				Toast.makeText(MainActivity.this, "分享成功", Toast.LENGTH_LONG).show();
			}
			
			@Override
			public void onFail() {
				Toast.makeText(MainActivity.this, "分享失败", Toast.LENGTH_LONG).show();
			}
			
			@Override
			public void onCancel() {
				Toast.makeText(MainActivity.this, "取消分享", Toast.LENGTH_LONG).show();
			}
		});
    }

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.shareText:
			shareToSinaWeiboInvoker.share("分享文本", "分享啊哈哈哈", null);
			break;
		case R.id.shareTextAndImage:
			Bitmap bm = BitmapFactory.decodeResource(MainActivity.this.getResources(), R.drawable.share_img);
			
			shareToSinaWeiboInvoker.share("分享图文", "分享文字+图片，哈哈哈", bm);
			break;

		default:
			break;
		}
	}

  
}
